package com.campus.dao;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.campus.entry.ManagerClass;
import com.campus.entry.ManagerStudent;
import com.campus.pojo.ManagerClassDto;
import com.campus.pojo.StudentClassDto;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface ManagerClassMapper extends BaseMapper<ManagerClass> {
    @Select("SELECT " +
            "c.name AS name,c.id AS id," +
            "c.created_time AS created_time, " +
            "c.class_desc AS class_desc, " +
            "t.teacher_name AS teacher_name, " +
            "a.name AS activity_name " +
            "FROM t_manager_class c " +
            "JOIN t_manager_teacher t ON c.teacher_id = t.id " +
            "JOIN t_manager_activity a ON c.activity_id = a.id "
            )
    List<ManagerClassDto> getManagerClassByClassId();
    @Select("SELECT tsic.student_id AS id, ts.stu_name AS stuName " +
            "FROM t_teaching_student_in_class tsic " +
            "JOIN t_manager_student ts ON tsic.student_id = ts.id " +
            "JOIN t_manager_class tc ON tsic.class_id = tc.id " +
            "WHERE tsic.class_id = #{classId} "
            )
    List<ManagerStudent> getStudents(@Param("classId") int classId);
    @Select("select activity_id from t_course where id=#{id}")
    Integer getActivityId(@Param("id") Integer id);

    @Select("SELECT tsic.student_id AS id, ts.stu_name AS stuName " +
            "FROM t_teaching_student_in_class tsic " +
            "JOIN t_manager_student ts ON tsic.student_id = ts.id " +
            "JOIN t_manager_class tc ON tsic.class_id = tc.id " +
            "WHERE tsic.class_id = #{classId} " +
            "AND tc.teacher_id = #{teacherId}")
    List<ManagerStudent> findStudentsByClassAndTeacher(@Param("classId") int classId, @Param("teacherId") int teacherId);

        @Select("SELECT " +
                "tc.id AS id, " +
                "tc.name AS name, " +
                "tc.created_time AS createdTime, " +
                "tc.class_desc AS classDesc, " +
                "ta.name AS activityName " +
                "FROM t_manager_class tc " +
                "JOIN t_manager_teacher tt ON tc.teacher_id = tt.id " +
                "JOIN t_manager_activity ta ON tc.activity_id = ta.id " +
                "WHERE tc.teacher_id = #{teacherId}")
        List<ManagerClassDto> findClassesByTeacherId(@Param("teacherId") Integer teacherId);
    @Select("SELECT " +
            "cl.name AS name,       " +
            "cl.class_desc AS classDesc,   " +
            "t.teacher_name AS teacherName " +
            "FROM t_teaching_student_in_class tsic " +
                    "JOIN t_manager_class cl ON tsic.class_id = cl.id " +
                    "JOIN t_manager_teacher t ON cl.teacher_id = t.id " +
                    "WHERE tsic.student_id = #{studentId}")
    List<StudentClassDto> getStudentClassInfo(@Param("studentId") Integer studentId);

}
